import 'dart:ui';

import 'package:flutter/material.dart';
import 'package:tender_flutter/constant/app_constant.dart';
import 'package:tender_flutter/constant/resource_path.dart';
import 'package:tender_flutter/constant/theme_colors.dart';
import 'package:tender_flutter/page/home/tender_list_page.dart';
import 'package:tender_flutter/router/router.dart';
import 'package:tender_flutter/router/router_map.gr.dart';
import 'package:tender_flutter/utils/screen_adaper.dart';
import 'package:tender_flutter/widgets/sticky_tabbar_delegate.dart';

class ArmyPage extends StatefulWidget {
  @override
  _ArmyPageState createState() => _ArmyPageState();
}

class _ArmyPageState extends State<ArmyPage>
    with SingleTickerProviderStateMixin {
  @override
  void initState() {
    super.initState();
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(body: _initBody());
  }

  /// 导航
  Widget _initAppBar() {}

  /// 内容
  Widget _initBody() {
    return NestedScrollView(
        headerSliverBuilder: (BuildContext context, bool innerBoxIsScrolled) {
          return <Widget>[
            SliverAppBar(
              forceElevated: innerBoxIsScrolled,
              backgroundColor: ThemeColors.colorType28,
              leading: FlatButton(
                child: Icon(
                  Icons.arrow_back_ios_rounded,
                  color: ThemeColors.colorWhite,
                ),
                onPressed: () {
                  LRouter.navigatorCtx(context).pop();
                },
              ),
              floating: false,
              expandedHeight: ScreenAdapter.height(330),
              elevation: 0,
              pinned: true,
              //可折叠的应用栏
              flexibleSpace: FlexibleSpaceBar(
                background: Container(
                  color: ThemeColors.colorWhite,
                  padding: EdgeInsets.only(
                      bottom: kToolbarHeight / 2 + ScreenAdapter.height(25)),
                  child: Image.asset(RPath.imgPath + "img_arm_zone.png",
                      fit: BoxFit.cover),
                ),
                title: _initSearchBar(),
                centerTitle: true,
                titlePadding: EdgeInsets.zero,
                collapseMode: CollapseMode.parallax,
              ),
            ),
            SliverPersistentHeader(
              pinned: false,
              delegate: StickyTabBarDelegate(
                minHeight: ScreenAdapter.height(120),
                maxHeight: ScreenAdapter.height(120),
                child: _initButtonView(),
              ),
            )
          ];
        },
        body:
            TenderListPage(tenderType: AppConstant.TENDERTYPE_ARMY, state: 1));
  }

  /// 搜索框
  Widget _initSearchBar() {
    final double topPadding = MediaQuery.of(context).padding.top;
    return GestureDetector(
        onTap: () {
          LRouter.navigatorCtx(context).push(Routes.searchListPage,
              arguments: SearchListPageArguments(isShowCity: false,
                  tenderType: AppConstant.TENDERTYPE_ARMY_SEARCH));
        },
        child: Container(
          height: kToolbarHeight + topPadding,
          width: ScreenAdapter.screenWidth() - 2 * ScreenAdapter.width(80),
          child: Container(
            height: double.infinity,
            // width: double.infinity,
            margin: EdgeInsets.only(
                left: ScreenAdapter.width(20),
                right: ScreenAdapter.width(20),
                top: topPadding + ScreenAdapter.height(15),
                bottom: ScreenAdapter.height(15)),
            decoration: BoxDecoration(
                color: ThemeColors.colorWhite,
                borderRadius:
                    BorderRadius.all(Radius.circular(ScreenAdapter.width(14))),
                boxShadow: [
                  BoxShadow(
                    blurRadius: 0.8, //阴影范围
                    spreadRadius: 0.2, //阴影浓度
                    color: ThemeColors.colorType21, //阴影颜色
                  ),
                ]),
            child: Row(
              mainAxisAlignment: MainAxisAlignment.center,
              mainAxisSize: MainAxisSize.min,
              children: <Widget>[
                // SizedBox(width: ScreenAdapter.width(80)),
                Image.asset(RPath.imgPath + "icon_gray_search.png",
                    width: ScreenAdapter.width(25)),
                SizedBox(width: ScreenAdapter.width(15)),
                Text(
                  "请输入招标关键词进行搜索",
                  style: TextStyle(
                      color: ThemeColors.colorType3,
                      fontSize: ScreenAdapter.sp(22)),
                ),
                // SizedBox(width: ScreenAdapter.width(80)),
              ],
            ),
          ),
        ));
  }

  /// 初始化集中采购 + 不对采购按钮
  Widget _initButtonView() {
    return Container(
      alignment: Alignment.center,
      height: ScreenAdapter.height(120),
      margin: EdgeInsets.only(
          left: ScreenAdapter.width(20),
          right: ScreenAdapter.width(20),
          bottom: ScreenAdapter.width(15)),
      color: ThemeColors.colorWhite,
      child: Row(mainAxisAlignment: MainAxisAlignment.spaceBetween, children: [
        Expanded(
            child: GestureDetector(
                onTap: () {
                  LRouter.navigatorCtx(context).push(Routes.armyChildPage,
                      arguments: ArmyChildPageArguments(stateType: 1));
                },
                child: Image.asset(RPath.imgPath + "img_arm_jizhong.png",
                    fit: BoxFit.contain))),
        SizedBox(width: ScreenAdapter.width(15)),
        Expanded(
            child: GestureDetector(
                onTap: () {
                  LRouter.navigatorCtx(context).push(Routes.armyChildPage,
                      arguments: ArmyChildPageArguments(stateType: 2));
                },
                child: Image.asset(RPath.imgPath + "img_arm_budui.png",
                    fit: BoxFit.contain))),
      ]),
    );
  }
}
